#include "EffectListParser.h"

EffectListParser::EffectListParser()
: m_effectsStarted(false)
{
}

void EffectListParser::parse(const QString& filename)
{
	QXmlSimpleReader reader;

	QFile file(filename);
	if(!file.open(QFile::ReadOnly))
	{
		QMessageBox message;
		message.setText("Failed to open: " + filename);
		message.exec();
	}

	QXmlInputSource* source = new QXmlInputSource(&file);

	reader.setContentHandler(this);
	reader.setErrorHandler(this);

	reader.parse(source);
}

bool EffectListParser::fatalError(const QXmlParseException& exception)
{
	qDebug() << "Fatal XML error: (" << exception.lineNumber() << ":" << exception.columnNumber() << ") - " << exception.message() << ".\n";
	return false;
}

bool EffectListParser::startElement(const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts)
{
	if(qName == "Effects")
	{
		qDebug() << "Starting effects...\n";
		m_effectsStarted = true;
		return true;
	}

	if(!m_effectsStarted)
		return true;

	//qDebug() <<
	m_effects[atts.value("name")] = atts.value("filename");

	return true;
}
